<!DOCTYPE html>
<html>
<head>
    <meta name="layout" content="main"/>
    <g:set var="entityName" value="${message(code: 'mortgage.label', default: 'Mortgage')}"/>
    <title>不良资产包</title>
    <style>
    .table>tbody>tr>td{
        vertical-align: middle;
    }
    @media screen and (min-width:1900px) and (max-width:1920px) {
        .flex{
            display: flex;justify-content: center;align-items: center;
        }
    }
    .select2-container .select2-choices .select2-search-field input,.select2-container .select2-choice,.select2-container .select2-choices{

        color: #999;
    }
    </style>
</head>

<body class="fixed-navbar fixed-sidebar">

<div class="small-header">
    <div class="hpanel">
        <div class="panel-body">
            <div id="hbreadcrumb" class="pull-right navFloatRight">
                <ol class="hbreadcrumb breadcrumb">
                    <li>
                        <span>CINDTATA PLS</span>
                    </li>
                    <li>
                        <span>不良资产包</span>
                    </li>
                </ol>
            </div>
        </div>
    </div>
</div>

<div class="content animate-panel">
    <div class="row">
        <g:form method="POST" action="${isO ? "transferList":"batchDetail"}" class="form-horizontal" role="form" id="form" onsubmit="return text();">
            <div class="hpanel hblue">
                <div class="panel-heading">
                    <div class="panel-tools">
                        <button class="btn btn-primary btn-xs" type="submit" onclick=""><i class="fa fa-search"></i> 查询</button>
                        <button class="btn btn-warning2 btn-xs" type="button" id="resetBtn">
                            <i class="fa fa-times"></i> 重置</button>
                    </div>
                    查询
                </div>
                <div class="panel-body seach-group" id="bug1">
                    %{--第一行--}%
                    <div class="row ">
                    <div class="form-group col-sm-4">
                        <label  class="col-sm-3 control-label">借款人名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="borrowName" id="borrowName" value="${params?.borrowName}" placeholder="请输入借款人姓名">
                        </div>
                    </div>

                    <div class="form-group col-sm-4">
                        <label class="col-sm-3 control-label">贷款编号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" name="externalId" id="externalId" value="${params?.externalId}" placeholder="请输入贷款编号">
                        </div>
                    </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">抵押品类型</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="buildingType" id="buildingType"
                                          from="${com.cindata.dictionary.BuildingTypeDict.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.buildingType}"
                                          noSelection="${["": '请选择抵押品状态']}"/>
                            </div>
                        </div>
                    </div>
                    %{--第二行--}%
                    <div class="row ">

                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" >还款方式</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="repayment" id="repayment"
                                          from="${com.cindata.dictionary.RepaymentModeDict.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.repayment}"
                                          noSelection="${["": '请选择还款方式']}"/>
                            </div>
                        </div>
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label" >处置措施</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="disposalMethod" id="disposalMethod"
                                          from="${com.cindata.dictionary.RiskWarningDisposalMethod.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.risk}"
                                          noSelection="${["": '请选择处置措施']}"/>
                            </div>
                        </div>
                    <div class="form-group col-sm-4">
                        <label class="col-sm-3 control-label" >处置阶段</label>
                        <div class="col-sm-9">
                            <g:select class="form-control" name="stage" id="stage"
                                      from="${com.cindata.dictionary.RiskWarningStage.list()}"
                                      valueMessagePrefix="status" optionKey="id" optionValue="name"
                                      value="${params?.risk}"
                                      noSelection="${["": '请选择处置措施']}"/>
                        </div>
                    </div>
                    </div>
                    %{--第三行--}%
                    <div class="row ">
                        <div class="form-group col-sm-4">
                            <label class="col-sm-3 control-label">贷款风险等级</label>
                            <div class="col-sm-9">
                                <g:select class="form-control" name="riskWarningLevel" id="riskWarningLevel"
                                          from="${com.cindata.RiskWarningLevel.list()}"
                                          valueMessagePrefix="status" optionKey="id" optionValue="name"
                                          value="${params?.level}"
                                          noSelection="${["": '请选择贷款风险等级']}"/>
                            </div>
                        </div>
                    <div class="form-group col-sm-4">
                        <label  class="col-sm-3 control-label">逾期期数</label>
                        <div class="col-sm-9  input-group">
                            <input type="text" class=" form-control " placeholder="请输入下限" id="overdueStart" maxlength="6"
                                   value="${params?.overdueStart}" name="overdueStart" />
                            <span class="input-group-addon">至</span>
                            <input type="text" class="form-control " placeholder="请输入上限" id="overdueEnd" maxlength="6"
                                   value="${params?.overdueEnd}" name="overdueEnd" />
                        </div>

                    </div>
                    <div class="p-t-xss" style="position: absolute;z-index: 2;right: 40px;">
                        次数
                    </div>

                    </div>

                </div>
            </div>
        </g:form>
    </div>

    <div class="row">
        <div class="hpanel hgreen">
            <div class="panel-heading">
                <div class="panel-tools">

                    <a class="showhide"><i class="fa fa-chevron-up"></i></a>
                </div>
                &nbsp;&nbsp;
            </div>

            <div class="panel-body no-padding">
                <div class="table-responsive">
                    <table cellpadding="1" cellspacing="1" class="table table-striped table-bordered table-hover text-center" id="esateTable">
                        <thead>
                        <tr>
                            <g:if test="${isO}">
                            <th style="width: 60px;"><input type="checkbox" class="i-checks allCheckbox" id="allOptionId"></th>
                            </g:if>
                            <g:sortableColumn property="externalId" title="序号"   params="${params}"/>
                            <g:sortableColumn property="batch" title="借款人"   params="${params}"/>
                            <g:sortableColumn property="buildingType" title="贷款编号"    params="${params}"/>
                            <g:sortableColumn property="estateStatus" title="手机号"   params="${params}"/>
                            <g:sortableColumn property="name" title="地址"    params="${params}"/>
                            <g:sortableColumn property="city" title="贷款余额"    params="${params}"/>
                            <g:sortableColumn property="district" title="贷款总额"    params="${params}"/>
                            <g:sortableColumn property="fullName" title="抵押品类型"    params="${params}"/>
                            <g:sortableColumn property="sourceAddress" title="还款方式"   params="${params}"/>
                            <g:sortableColumn property="sourceBuildArea" title="月还款金额"   params="${params}"/>
                            <g:sortableColumn property="registerFullName" title="贷款状态"   params="${params}"/>
                            <g:sortableColumn property="registerAccount" title="逾期期数"    params="${params}"/>
                            <g:sortableColumn property="registerDate" title="逾期天数"    params="${params}"/>
                            <g:sortableColumn property="cashability" title="贷款风险等级"   params="${params}"/>
                            <g:sortableColumn property="latestEvaluatePrice" title="处置阶段"   params="${params}"/>
                            <g:sortableColumn property="latestEvaluateDate" title="处置措施"   params="${params}"/>
                            <g:if test="${isO}">
                            <g:sortableColumn property="latestEvaluateDate" title="操作项"   params="${params}"/>
                            </g:if>
                        </tr>
                        </thead>
                        <tbody>
                        <g:each in="${list}">
                            <tr>
                                <g:if test="${isO}">
                                <td><input type="checkbox" class="i-checks everyCheckbox" name="everyCheckbox" value="${it?.id}"></td>
                                 </g:if>
                                <td >${it.id ? it?.id : "-"}</td>
                                <td>${it?.mortgage?.borrName ? it?.mortgage?.borrName : "-"}</td>
                                <td>${it?.mortgage?.externalId ? it?.mortgage?.externalId : "-"}</td>
                                <td>${it?.mortgage?.borrPhone ? it?.mortgage?.borrPhone : "-"}</td>
                                <td>${it?.mortgage?.borrAddress ? it?.mortgage?.borrAddress : "-"}</td>
                                <td>${it?.mortgage?.loansBalance ? it?.mortgage?.loansBalance : "-"}</td>
                                <td>${it?.mortgage?.loansAmount ? it?.mortgage?.loansAmount : "-"}</td>
                                <td>${it?.mortgage?.collateral?.estate?.buildingType?.name ? it?.mortgage?.collateral?.estate?.buildingType?.name : "-"}</td>
                                <td>${it?.mortgage?.curRepaymentMode?.name ? it?.mortgage?.curRepaymentMode?.name : "-"}</td>
                                <td>${it?.mortgage?.borrDepositBaseOnCurrent ? it?.mortgage?.borrDepositBaseOnCurrent : "-"}</td>
                                <td>${it?.mortgage?.mortgageStatus?.name ? it?.mortgage?.mortgageStatus?.name : "-"}</td>
                                <td>${it?.mortgage?.curDefaultingDuration ? it?.mortgage?.curDefaultingDuration : "-"}</td>
                                <td>180</td>
                                <td>次级</td>
                                <td>${it?.stage?.name ? it?.stage?.name : "-"}</td>
                                <td>${it?.disposalMethod?.name ? it?.disposalMethod?.name : "-"}</td>
                            <g:if test="${isO}">
                                <td>
                                    <div style="margin-bottom: 2px;">
                                        <a href="#" data-id="${it?.id}" class="btn btn-xs btn-outline btn-success handleButton">
                                            转让
                                        </a>
                                    </div>
                                </td>
                            </g:if>

                            </tr>
                        </g:each>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="panel-footer">
                <div class="pagination">
                    <g:paginate action="transferList" total="${count ?: 0}" params="${params}"/>
                </div>
                <g:if test="${isO}">
                    <div style="display: flex;justify-content: center;">
                        <button class="btn w-xs btn-success"  data-id="-1" style="margin-left: 20px;">批量转让</button>
                    </div>
                </g:if>

            </div>
        </div>
    </div>
</div>

%{--出入库申请--}%
<div class="modal fade" id="outOfStorageModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="color-line"></div>

            %{--<div class="modal-header">--}%
                %{--<h5 class="modal-title">出入库申请</h5>--}%
            %{--</div>--}%

            <div class="modal-body">
                <div class="form-group">
                    <label class="col-md-3 control-label">资产管理机构</label>
                    <div class="col-sm-6">
                        <input type="hidden" name="collateralId" id="collateralId" value="">
                        <g:select class="form-control" name="accountId" id="accountId"
                                  from="${com.cindata.Account.executeQuery("from Account where type.code = 'ManagementAccount'")}"
                                  valueMessagePrefix="status" optionKey="id" optionValue="name"
                                  value=""
                                  noSelection="${['-1': '请选择资产管理机构']}"/>
                    </div>
                </div>
            </div>

            <div class="hr-line-dashed"></div>

            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="confirm">确定</button>
                <button type="button" class="btn btn-default " data-dismiss="modal" >取消</button>
            </div>
        </div>
    </div>
</div>


<g:javascript>


    $("input[name='evaluateType']").bind("click",function()
    {
       if ($(this).val() == 10)
       {
            $('#evaluateAccount').removeClass("hidden");
       }
       else
       {
            $('#evaluateAccount').addClass("hidden");
       }
    });


    var checkAll =$('.allCheckbox');  //全选的input
    var checkboxs =$('.everyCheckbox'); //所有单选的input

    checkAll.on('ifChecked ifUnchecked',function(event){
        if(event.type == 'ifChecked'){
            checkboxs.iCheck('check');
        }else{
            checkboxs.iCheck('uncheck');
        }
    });

    checkboxs.on('ifChanged',function(event){
        if(checkboxs.filter(':checked').length == checkboxs.length){
            checkAll.prop('checked',true);
        }else{
            checkAll.prop('checked',false);
        }
        checkAll.iCheck('update');
    });

    //多条评估
    $(".btn-success").click(function(){
         ids =  $(this).attr("data-id")
        if(ids == '-1'){
            ids =  $("input:checkbox[name='everyCheckbox']:checked").map(function(index,elem) {
            return $(elem).val();
        }).get().join(',');
        }
        if(!ids){
            toastr.error('请选择押品！');
            return
        }
         $('#outOfStorageModal').modal('show')


    });

    $("#confirm").click(function(){
        var accountId = $("#accountId").val()
        if(accountId == "-1"){
               toastr.error('请选择一个资产管理机构！');
               return
        }
         swal({
            title: "确定批量转让？",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            closeOnConfirm: true
        },
        function(){
            $.ajax({
                url:'/transferBatch/batchTransfer',
                data:{
                    ids:ids,
                    accountId:accountId
                    },
                type:"post",
                success:function(data)
                {
                    if(data.status=="success"){
                        window.location.reload()
                    }else{
                        swal("转让失败，请稍后重试", "", "error");
                    }
                }
            })
        });
     })
    //取消按钮事件
    $(".cancelButton").click(function(){
        checkboxs.iCheck('uncheck');
    });
    function searchMap() {
        var city = $("#city").val();
        if(city=="-1"){
            toastr.error('请选择城市');
            return
        }
        window.location.href="/newMap/cluster?currentMap=clusterMap&city="+$("#city").val()+"&district="+$("#district").val()+"&communityId="+$("#communityId").val();
    }
    $(function () {
        $('#datepicker').datepicker({
            language: 'zh-CN'
        });
        $("#datepicker").on("changeDate", function(event) {
            $("#my_hidden_input").val(
                    $("#datepicker").datepicker('getFormattedDate')
            )
        });

        $('.input-group.date').datepicker({ });
        $('.input-daterange').datepicker({ });
        var flag;
        $("#city").bind("change", function(){
            if('${params.district}'== $("#district option:selected").val()&&flag!=true && '${params.district}' != '-1'){
                flag=true
                return
            }
            $("#district option").remove();
            $("#s2id_district span:first").html("请选择行政区");
            var city = $("#city").val()
            $("#district").append("<option value='-1' >请选择行政区</option>")
            if(city=='-1'){
                return
            }
            $.ajax({
                url: "/estate/districtList",
                type: "POST",
                data: {'city': city} ,
                success: function(result){
                    for(var i=0; i < result.districtList.length; i++){
                        $("#district").append("<option value=" + result.districtList[i].zoneNumber + ">" + result.districtList[i].name + "</option>")
                    }
                }
            });
        });
        $("#city").change();
    });

    //重置按钮
    $("#resetBtn").click(function () {
        $("#communityId").val("");
        $("#s2id_city span:first").html("请选择城市");
        $("#city").val("");
        $("#s2id_district span:first").html("请选择行政区");
        $("#district").val("");
        $('#s2id_estateStatus span:first').html('请选择押品状态');
        $('#estateStatus').val('');
        $("#sourceAddress").val("");
        $("#name").val("");
        $('#s2id_risk span:first').html('请选择押品风险');
        $('#risk').val("");
        $('#s2id_mortgageStatus span:first').html('请选择贷款状态');
        $('#mortgageStatus').val("");
        $('#s2id_buildingType span:first').html('请选择房屋类型');
        $('#buildingType').val("");
        $("#buildAreaStart").val("");
        $("#buildAreaEnd").val("");
        $('#s2id_cashability span:first').html('请选择变现能力');
        $("#cashability").val("")
    });

    // 限制
    $(function(){
        function text(){
            if(buildAreaStart.value<0||buildAreaStart.value>214748||buildAreaEnd.value<0||buildAreaEnd.value>214748){
                toastr.error('值应0-214748之间');
                buildAreaStart.value='';
                buildAreaEnd.value='';
            }
        }

    })
</g:javascript>

</body>
</html>
